<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-row">
        <div class="layui-input-inline">
            <select id="record_type" name="record_type" class="layui-input" style="width: 150px;">
            <option value="">全部类型</option>
            <volist name="record_type" id="vo">
                <option value="{$key}">{$vo}</option>
            </volist>
            </select>
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input date" readonly id="start" placeholder="记录时间-起">
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input date" readonly id="end" placeholder="记录时间-止">
        </div>
        <div class="layui-input-inline">
            <button class="layui-btn" data-type="search">搜索</button>
            <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
        </div>
    </div>
    <table class="layui-table" lay-data="{cellMinWidth: 80, height:'auto', url:'{$url}', page: true,limit: 10, id:'cash',type: 'checkbox'}" lay-filter="cash">
        <thead>
        <tr>
            <th lay-data="{checkbox:true,fixed: true}"></th>
            <th lay-data="{field:'id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'driver_name', width:100,align:'center'}">姓名</th>
            <th lay-data="{field:'money', width:120, sort: true, align:'center', templet:'#moneyTpl'}">金额</th>
            <th lay-data="{field:'record_type', width:120, align:'center'}">类型</th>
            <th lay-data="{field:'common_id', width:240, sort: true, align:'center'}">订单ID</th>
            <th lay-data="{field:'add_time', width:160, sort: true, align:'center'}">记录时间</th>
        </tr>
        </thead>
    </table>
    <div class="layui-hide" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </div>
    <!--<script type="text/html" id="moneyTpl">-->
        <!--{{#if(d.money!=0){}}-->
        <!--<span>{{(d.money/100).toFixed(2)}}元</span>-->
        <!--{{#}}}-->
    <!--</script>-->

    <script>
        layui.use(['table','laydate'], function () {
            var table = layui.table
                ,laydate = layui.laydate
                ,form = layui.form;

            laydate.render({
                elem:'#start'
            });
            laydate.render({
                elem:'#end'
            });
            //监听工具条
            table.on('tool(cash)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var id = data.record_id;
                if (layEvent === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        var url = "{:url('del')}";
                        $.post(url, {'id': id}, function (res) {
                            switch (res['status']){
                                case 1:
                                    obj.del();
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        }, 'json');
                        layer.close(index);
                    });
                }
            });

            var active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var record_type = $('#record_type').val();

                    var reset = $('#reset');
                    if(start||end||record_type){
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('cash', {
                            url: '/admin/cash/search',
                            where: {
                                start : start,
                                end : end,
                                driver_id : "{$driver_id}",
                                record_type : record_type
                            } //设定异步数据接口的额外参数
                        });
                    }else{
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('cash', {
                            url: '/admin/cash/table',where:{driver_id : "{$driver_id}",action:'flow'}
                        });
                    }
                    $('.layui-input').each(function () {
                        $(this).val('');
                    });
                    $('.layui-this').each(function () {
                        $(this).removeClass('layui-this');
                    });
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</block>
